--处理呼叫分机的事件

freeswitch.consoleLog("info","进入channel——create");

--获取方向
local direct=event:getHeader("Caller-Direction");

--取出非外呼，非call center的呼叫
 freeswitch.consoleLog("info","direct->"..direct);
if ( direct ~= "outbound" )  then
	
	return "break";
end


local ccagent=event:getHeader("variable_cc_agent");
freeswitch.consoleLog("info","direct->"..ccagent);
if (ccagent == nil) then
	return "break";
end


local callnum=event:getHeader("Caller-Caller-ID-Number");
 freeswitch.consoleLog("info","direct->"..callnum);
if(callnum == nil) then
	return "break";
end




local  sessionuuid=event:getHeader("variable_cc_member_session_uuid");
 freeswitch.consoleLog("info","direct->"..sessionuuid);
if(sessionuuid == nil) then
	return "break";
end;






--那么这里的就应该是从callcenrer里面出队列的时候呼叫分机号码了！
--这个时候给应用发送事件，通知分机
 freeswitch.consoleLog("info","客户已经发给坐席"..sessionuuid..ccagent);
 local api=freeswitch.API();

local uniquereply=api:executeString("uuid_getvar "..sessionuuid.." 'uuid'"); 
uniquereply=string.gsub(uniquereply, "^%s*(.-)%s*$", "%1");

 freeswitch.consoleLog("info","offferresult"..uniquereply);

  local event = freeswitch.Event("CUSTOM", "NECO:BEFORE_BRIDGE");
  event:addHeader("Caller-Orig-Caller-ID-Number",callnum);
  event:addHeader("Caller-Callee-ID-Number",ccagent);
  event:addHeader("Unique-ID",uniquereply);
  event:fire();



